<?php

	include_once "../library/DbConnection.php";
	include_once "../globals.php";
	include_once "../got/Movement.php";
	include_once "../got/Interruptor.php";

	class GetMovementAndPositions
	{
		private $db;



		/****************
		** CONSTRUCTOR **
		****************/
		public function __construct()
		{
			session_start();
			$this->db = new DbConnection($GLOBALS["db_server"], $GLOBALS["db_login"], $GLOBALS["db_pass"], $GLOBALS["db_name"]);
			$this->db->connect();
			 
		}



		/*******************
		** PUBLIC METHODS **
		*******************/

		/** Get the movement of the user
		* @return	{Object}	:	"movement" -> The movement of the user
		* 					"session"  -> Session state (true/false);
		**/
		public function get($id)
		{
			//If the id to get isn't the good one then put it at null
			if($id != $_SESSION['virtual_id'])
				$id = "";

			$ret		= array();
			if(!isset($_SESSION['user_id']))
				$ret["session"]	= false;
			else{
				$movement			= new Movement();
				$interruptor		= new Interruptor();
				$movResult		= $movement->get($id);
				$intResult		= $interruptor->get($id);
				$ret["session"]	= true;
				$ret["movement"]	= ($movResult["movement"] == "")?		array() : $movResult["movement"];
				$ret["positions"]	= ($intResult["positions"] == "")?		array() : $intResult["positions"];
			}
			return $ret;
		}
	}
?>